<?php
defined('_JEXEC') or die('Restricted access');
$img_dir = JPATH_SITE.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'fileupload'.DIRECTORY_SEPARATOR;
$img_path = JURI::root(true).'/images/fileupload/';
$title = ($this->id)?"Sửa thông tin máy photocopy":"Thêm máy photocopy mới";
?>

<div class='tab_content' id="tab_create_engine">
	<div class='container-fluid container_root margin10'>
		<div class='row-fluid'>
			<div class='widget widget-padding span12'>
				<div class='widget-header'>
					<i class="icon-plus"></i>
					<h5><?php echo $title ?></h5>
				</div>
				<div class='widget-body'>
								
					<form class='form' id="form_create_engine" method="post" enctype="multipart/form-data" action="index.php">
						<div class='row-fluid'>
							<div class='span6'>
								<button type="submit" class='btn btn-primary'>
									<i class='icon-ok icon-white'></i>
									<?php echo JText::_("COM_KETNOI_SAVEBTN") ?>
								</button>
								
								<a type="submit" href="#engine" class='btn'>
									<i class='icon-reorder icon-white'></i>
									Danh sách
								</a>
							</div>
						</div>
						
						<div class="row-fluid margin10">
							<div class='span12'>
								<div class="row-fluid">
									<div class='span4'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_CODE") ?>
												<em>*</em>
											</label>
					                        <div class="controls row-fluid">
					                            <input type='text' value='<?= $this->row->ma ?>' required='required' name='ma' class="span12"/>
					                       		<?php if($this->id): ?>
					                       			<input type='hidden' id='oldma' value='<?= $this->row->ma ?>' /> 
					                       		<?php endif; ?>
					                        </div>
				                        </div>
									</div>
									
									<div class='span4'>
										<div class="control-group">
				                          	<label>
												<?php echo JText::_("COM_KETNOI_ENGINENAME") ?>
												<em>*</em>
											</label>
					                        <div class="controls row-fluid">
					                            <input value='<?= $this->row->ten ?>' type='text' required='required' name='ten' class="span12"/>
					                        	<?php if($this->id): ?>
					                       			<input type='hidden' id='oldten' value='<?= $this->row->ten ?>' /> 
					                       		<?php endif; ?>
					                        </div>
				                        </div>
									</div>
									
									<div class='span4'>
										<div class="control-group">
				                          	<label>
												<?php echo JText::_("COM_KETNOI_DONVITINH") ?>
												<em>*</em>
											</label>
					                        <div class="controls row-fluid">
					                        	<div class='span10 chosen_group'>
						                            <select data-toggle='chosen' id="photocopy_donnvi" search='false' name="id_donvi">
						                            	<?php foreach ($this->donvi as $donvi): ?>
						                            		<?php $selected = $donvi->id == $this->row->id_donvi?"selected":"" ?>
						                            		<option <?= $selected ?> value="<?php echo $donvi->id ?>">
						                            			<?php echo $donvi->ten ?>
						                            		</option>
						                            	<?php endforeach; ?>
						                            </select>
						                           	<a class='btn btn-info fix-btn' onclick='showModalCreateDonvi("photocopy_donnvi")'>
														<i class='icon icon-plus'></i>
													</a>					                            
					                            </div>
					                        </div>
				                        </div>
									</div>
									
								</div>
								
								<div class="row-fluid">		
																	
									<div class='span4'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_SOTHANGBAOHANH") ?>
				                          		<em>*</em>
											</label>
					                        <div class="controls row-fluid custom">
					                            <input type='text' value='<?= $this->row->sothangbaohanh ?>' name='sothangbaohanh' class="span12"/>
					                        </div>
				                        </div>
									</div>
									
									<div class='span4'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_SOCOUNTERBAOHANH") ?>
				                          		<em>*</em>
											</label>
					                        <div class="controls row-fluid custom">
					                            <input type='text' required='required' value='<?= $this->row->sodungluongbaohanh ?>' name='sodungluongbaohanh' class="span12"/>
					                        </div>
				                        </div>
				                    </div> 
				                    
				                    <div class='span4'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_GHICHU") ?>
											</label>
					                        <div class="controls row-fluid">
					                        	<textarea name='ghichu' class="span12"><?= $this->row->ghichu ?></textarea>
					                        </div>
				                        </div>
									</div>   
								</div>
								
								<div class="row-fluid">
									
									<div class='span12'>
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		<?php echo JText::_("COM_KETNOI_HINHANH") ?>
											</label>
					                        <div class="controls row-fluid">
					                        	<div class='browse_button'>
													<a class='btn browse_button' onclick="addmorefile(this,'fileList','file')" id="fileSelect">
														<?php echo JText::_("COM_KETNOI_CHONHINH") ?>
													</a> 
													<div id="fileList">
														<?php $img_list = json_decode($this->row->hinhanh); ?>
														<?php if(count($img_list) > 0 && !empty($img_list)): ?>
															<?php foreach($img_list as $img): ?>
																<?php if(JFile::exists($img_dir.$img)): ?>
																	<div>
																		<img class="img-polaroid" src="<?= $img_path . $img ?>" height="60">
																		<img style="display: none;" class="img_tmp" src="<?= $img_path . $img ?>" height="60">
																		<a img_name='<?= $img ?>'>
																			<i class="icon-remove"></i>
																		</a>
																	</div>
																<?php endif; ?>
															<?php endforeach; ?>
														<?php endif; ?>
													  	<input type="hidden" id="delete_file" name="delete_file" value="[]" />
													  	<input type="hidden" name="old_file" value='<?= $this->row->hinhanh ?>' />
													</div>
					                        	</div>
					                        </div>
				                        </div>
									</div>
									 
								</div>
							</div>
						</div>
						
						<input type="hidden" name="option" value="com_ketnoi" />
						<input type="hidden" name="view" value="engine" />
						<input type="hidden" name="task" value="engine.save" />
						<input type="hidden" name="layout" value="create" />
						<input type="hidden" name="tmpl" value="raw" />
						<input type="hidden" name="quickcreate" value="<?= JRequest::getVar("quickcreate",0) ?>" />
						<input type="hidden" name="client_update" value="<?= JRequest::getVar("client_update","") ?>" />
						<?php if($this->id): ?>
						<input type="hidden" name="id" value="<?= $this->id ?>" />
						<?php endif; ?>
					</form>
				</div>
				
			</div>
		</div>
	</div>
</div>

<script>
	<?php if($this->id): ?>
		setHash("edit_engine",<?= json_encode(array("id"=>$this->id)) ?>);
	<?php endif; ?>

</script>